package com.atguigu.c_designed.m3beheviorModel.b10Strategy.v2;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class PromotionStrategyFacory {
 
     private static final PromotionStrategy EMPTY = new EmptyStrategy();
     private static Map<String, PromotionStrategy> PROMOTIONS = new HashMap<>();
 
     static {
         PROMOTIONS.put(PromotionKey.COUPON, new CouponStrategy());
         PROMOTIONS.put(PromotionKey.CASHBACK, new CashBackStrategy());
         PROMOTIONS.put(PromotionKey.GROUPBUY, new GroupBuyStrategy());
     }
 
     private PromotionStrategyFacory() {
     }

     public static PromotionStrategyFacory getInstance(){
         return new PromotionStrategyFacory();
     }
 
     public  PromotionStrategy getPromotionStrategy(String promotionKey) {
         PromotionStrategy strategy = PROMOTIONS.get(promotionKey);
         return strategy == null ? EMPTY : strategy;
     }
 
     public  Set<String> getPromotionKeys() {
         return PROMOTIONS.keySet();
     }
 
     private interface PromotionKey {
         String COUPON = "COUPON";
         String CASHBACK = "CASHBACK";
         String GROUPBUY = "GROUPBUY";
     }
 }